const {promisify} = require('util')

async function queueIn(item) {
  const redis = require('redis').createClient()
  const itemStr = JSON.stringify(item)
  const lpush = promisify(redis.lpush).bind(redis)
  const publish = promisify(redis.publish).bind(redis)

  await lpush('fehub', itemStr)
  await publish('notify', JSON.stringify({title: item.title, url: item.url}))
  isQuit = redis.quit()
  isQuit ? console.log('lagou:关闭redis成功'.green) : console.log('lagou:关闭redis失败'.green)
}

module.exports = {
  queueIn
}